package org.example.gradleDemo.lists;

import gnu.trove.iterator.TLongObjectIterator;
import gnu.trove.map.hash.TLongObjectHashMap;
import org.example.gradleDemo.jmh.Trade;

import java.util.LinkedHashMap;
import java.util.Map;

public final class TLinkedMapDemo {
    private final TLongObjectHashMap<Trade> _tradeMap = new TLongObjectHashMap<>(1000);
    public Trade Last;

    public TLinkedMapDemo() {
        Last = null;
    }

    public void Add(final Trade trade) {
        _tradeMap.put(trade.id(), trade);
        if (_tradeMap.size() > 1) {
            Last = trade;
        }
    }

    public Trade getFirst() {
        return _tradeMap.isEmpty() ? null : _tradeMap.iterator().value();
    }

    public Trade getSecond() {
        if (_tradeMap.size() < 2) {
            return null;
        }
        if (this.Last != null) return this.Last;


        return Last;
    }

    public Trade getPreviousLast() {
        final int size = _tradeMap.size();
        if (size < 2) {
            return null;
        }
        int i = size;
        Trade trade = null;

        return trade;

    }

    public void Remove(final Long tradeId) {
        _tradeMap.remove(tradeId);
        if (this.Last != null && this.Last.id() == tradeId.longValue()) {
            this.Last = null;
        }
    }
}
